package com.yanyq.week02.servlet;


import com.yanyq.week02.config.ServletRequestConfigSource;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Set;

@WebServlet(urlPatterns = "/microprofile/config")
public class MicroprofileConfigServlet extends HttpServlet {
//    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        ServletRequestConfigSource servletRequestConfigSource = new ServletRequestConfigSource(req);
//        Set<String> sets = servletRequestConfigSource.getPropertyNames();
//        Map<String, String> map = servletRequestConfigSource.getProperties();
//        PrintWriter writer = resp.getWriter();
//        writer.write(sets.toString());
//        writer.write(map.toString());
//    }
//
//    @Override
//    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        this.doPost(req, resp);
//    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletRequestConfigSource servletRequestConfigSource = new ServletRequestConfigSource(request);
        Set<String> sets = servletRequestConfigSource.getPropertyNames();
        Map<String, String> map = servletRequestConfigSource.getProperties();
        response.setCharacterEncoding("GBK");
        PrintWriter writer = response.getWriter();
        writer.write(sets.toString());
        writer.write(map.toString());
    }
}
